package com.chookss.home.audit.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.chookss.R;
import com.chookss.base.BaseViewHolderEx;
import com.chookss.home.entity.ReimbursementDetailEntity;
import com.chookss.tools.GlideUtils;
import com.chookss.tools.MyEvent;
import com.chookss.tools.Utils;
import com.chookss.tools.bigImage.ImagePreview;
import com.chookss.tools.bigImage.bean.ImageInfo;
import com.chookss.view.MyRoundLayout;
import com.johnrambo.ktea.common.klogutil.KLog;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ShopImagsAdapter extends BaseQuickAdapter<String, BaseViewHolderEx> {
    private Context context;
    private int width, height;
    private List<ImageInfo> imageInfoList = new ArrayList<>();
    private int type = 0;//0默认可以编辑删除1不可以编辑
    private int parent_position = 0;//父类所在下标

    public ShopImagsAdapter(int layoutResId, Context context, @io.reactivex.annotations.Nullable List<String> data) {
        super(layoutResId, data);
        this.context = context;
        width = (Utils.getScreenWidthPixel(context) - Utils.dip2px(context, 60)) / 4;
        height = width;
        setUrlList(data);
    }

    public void setUrlList(List<String> data) {
//        for (int i = 0; i < data.size(); i++) {
//            ImageInfo imageInfo = new ImageInfo();
//            if (data.get(i).getPictureUrl().contains("x-oss-process")) {
//                imageInfo.setThumbnailUrl(data.get(i).getPictureUrl().split("\\?")[0]);// 缩略图url
//                imageInfo.setOriginUrl(data.get(i).getPictureUrl().split("\\?")[0]);// 缩略图url
//            } else {
//                imageInfo.setThumbnailUrl(data.get(i).getPictureUrl());// 缩略图url
//                imageInfo.setOriginUrl(data.get(i).getPictureUrl());// 缩略图url
//            }
//            imageInfoList.add(imageInfo);
//        }
    }

    @Override
    protected void convert(BaseViewHolderEx helper, String item) {
        RelativeLayout myRl = helper.getView(R.id.myRl);
        RelativeLayout rlAdd = helper.getView(R.id.rlAdd);
        ImageView ivBg = helper.getView(R.id.ivBg);
        ImageView ivDelete = helper.getView(R.id.ivDelete);
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) myRl.getLayoutParams();
        params.height = height;
        params.width = width;
        myRl.setLayoutParams(params);
        if (Utils.isNull(item)) {
            ivBg.setVisibility(View.GONE);
            ivDelete.setVisibility(View.GONE);
            rlAdd.setVisibility(View.VISIBLE);
        } else {
            ivBg.setVisibility(View.VISIBLE);
            ivDelete.setVisibility(View.VISIBLE);
            rlAdd.setVisibility(View.GONE);
            GlideUtils.load(context, item, ivBg, R.drawable.default_news);
        }

        ivDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map<String, String> map = new HashMap<>();
                map.put("position", helper.getItemPosition() + "");
                map.put("parent_position", parent_position + "");
                map.put("deleteReimbursementPic", "deleteReimbursementPic");
                EventBus.getDefault().post(new MyEvent(map));

            }
        });
        rlAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(new MyEvent("Shop_Add"));

            }
        });
    }

}
